/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pricecomparison.websitereader.purelandreader;

import java.util.ArrayList;
import javax.swing.JLabel;
import pricecomparison.PriceComparisonView;

/**
 *
 * @author Jim Simon
 */
public class PL_HomePageReader {
    final String URL = "http://www.purelandsupply.com";
    
    public void beginSearch(String page, boolean newSheet, JLabel l) throws java.net.MalformedURLException, jxl.write.WriteException, java.io.IOException {            
        try {
            if (newSheet)
                PriceComparisonView.excelWriter.newSheet(PriceComparisonView.excelWriter.MFER_PURELAND);

            PL_ItemListReader group = new PL_ItemListReader(page);
            ArrayList<String> pages = new ArrayList();
            pages.addAll(group.getPages());
            // Do first page
            group.beginSearch(l);

            // Do rest of pages
            for (int j = 0; j < pages.size(); j++) {   
                group = new PL_ItemListReader(pages.get(j));
                group.beginSearch(l);
            }
        } catch (java.net.MalformedURLException e) {
            throw e;
        } catch (jxl.write.WriteException e) {
            throw e;
        } catch (java.io.IOException e) {
            throw e;
        }
    }
    
    protected String extractLink(String line) {
        // Find beginning
        String key = "<a href=\"";
        int pos = line.indexOf(key);
        
        // Consume upto line
        line = line.substring(pos + key.length());
        
        // Find end
        key = "\">";
        pos = line.indexOf(key);
        
        // Cut away end of line
        line = line.substring(0, pos);

        return line;
    }
}
